package com.kun.feign;

import com.kun.feign.interceptor.AccessTokenInterceptor;
import com.kun.feign.sentinel.KunSentinelFeign;
import feign.Feign;
import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

/**
 * @author kun.li
 */
public class KunFeignAutoConfig {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return new AccessTokenInterceptor();
    }

    @Bean
    @Scope("prototype")
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = "feign.sentinel.enabled")
    public Feign.Builder feignSentinelBuilder() {
        return KunSentinelFeign.builder();
    }
}
